from helpers import Fetching
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


class MainPage(webapp.RequestHandler):
    """ Show headline in page (legendary) page class """
    def get(self):
        HeadlineTitle, HeadlineURL = Fetching.headlineForStock(self.request.get('sQuery'))
        if HeadlineTitle==-1:
            self.response.out.write("No article is available")
        else:
    
            #self.response.out.write("<script type=\"text/javascript\">window.location = \"%s\"</script>" % HeadlineURL)
            
            self.redirect(HeadlineURL)
        

application = webapp.WSGIApplication(
                                     [('/showHeadline.html', MainPage)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()